package com.office.web.core.config;

import com.office.common.config.OfficeConfig;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import io.swagger.v3.oas.models.Components;
import io.swagger.v3.oas.models.OpenAPI;
import io.swagger.v3.oas.models.info.Contact;
import io.swagger.v3.oas.models.info.Info;
import io.swagger.v3.oas.models.security.SecurityRequirement;
import io.swagger.v3.oas.models.security.SecurityScheme;
import org.springdoc.core.models.GroupedOpenApi;

/**
 * Swagger3的接口配置
 *
 * @author 数字牧马人
 */

//http://localhost:8000/swagger-ui.html
@Configuration
public class SwaggerConfig {
    /** 系统基础配置 */
    @Autowired
    private OfficeConfig officeConfig;

    @Bean
    public GroupedOpenApi publicApi() {
        return GroupedOpenApi.builder()
                .group("public")
                .pathsToMatch("/**")
                .build();
    }

    @Bean
    public OpenAPI customOpenApi() {
        return new OpenAPI()
                .components(new Components()
                        .addSecuritySchemes("bearer-key",
                                new SecurityScheme()
                                        .type(SecurityScheme.Type.HTTP)
                                        .scheme("bearer")
                                        .bearerFormat("JWT")))
                .addSecurityItem(new SecurityRequirement().addList("bearer-key"))
                .info(new Info()
                        .title("Office AI 系统接口文档")
                        .description("用于管理集团旗下公司的人员信息,具体包括XXX,XXX模块...")
                        .contact(new Contact().name(officeConfig.getName()))
                        .version("版本号:" + officeConfig.getVersion()));
    }
}
